//
//  GetDateModel.m
//  MonitoringNetwork
//
//  Created by admin on 2017/12/20.
//  Copyright © 2017年 wtmcxlm. All rights reserved.
//

#import "GetDateModel.h"

@interface GetDateModel()



@end


@implementation GetDateModel

+ (NSArray *)getYearByCurrentDate:(NSDate *)currentday
{
    NSMutableArray *yearArr = [NSMutableArray array];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy"];
    //年份
    int year = [[formatter stringFromDate:currentday] intValue];
     for (int i = year-3; i<=year; i++) {
         NSString *str = [NSString stringWithFormat:@"%d",i];
         [yearArr addObject:str];
     }
    return yearArr.copy;
}
+ (NSArray *)getMounthByCurrentDate:(NSDate *)currentday
{
    NSMutableArray *mounthArr = [NSMutableArray array];

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"MM"];
    int mounth = [[formatter stringFromDate:currentday] intValue];
    for (int i = 1; i<=mounth; i++) {
        NSString *str = [NSString stringWithFormat:@"%d",i];
        [mounthArr addObject:str];
    }
    return mounthArr.copy;
}
+ (NSArray *)getDayByCurrentDate:(NSDate *)currentday
{
    NSMutableArray *dayArr = [NSMutableArray array];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"dd"];
    int day = [[formatter stringFromDate:currentday] intValue];
    for (int i = 1; i<=day; i++) {
        NSString *str = [NSString stringWithFormat:@"%d",i];
        [dayArr addObject:str];
    }
    return dayArr.copy;
}

+ (NSArray *)getNormalMouthWithYear:(NSString *)year andCurrentDate:(NSDate *)currentday
{
    
    NSMutableArray *mounthArr = [NSMutableArray array];
    NSDateFormatter *formatter1 = [[NSDateFormatter alloc] init];
    [formatter1 setDateFormat:@"yyyy"];
    NSDateFormatter *formatter2 = [[NSDateFormatter alloc] init];
    [formatter2 setDateFormat:@"MM"];
    
    int yearNum = [[formatter1 stringFromDate:currentday] intValue];
    int mounthNum = [[formatter2 stringFromDate:currentday] intValue];
    if ([year intValue] == yearNum) {
        for (int i = 1; i<=mounthNum; i++) {
            NSString *str = [NSString stringWithFormat:@"%d",i];
            [mounthArr addObject:str];
        }
    }else{
        for (int i = 1; i<=12; i++) {
            NSString *str = [NSString stringWithFormat:@"%d",i];
            [mounthArr addObject:str];
        }
    }
    return mounthArr.copy;
}

+ (NSArray *)getNormalDayWithMounth:(NSString *)mounth andYear:(NSString *)year andCurrentDate:(NSDate *)currentday
{
    
    NSMutableArray *dayArr = [NSMutableArray array];
    NSDateFormatter *formatter1 = [[NSDateFormatter alloc] init];
    [formatter1 setDateFormat:@"yyyy"];
    NSDateFormatter *formatter2 = [[NSDateFormatter alloc] init];
    [formatter2 setDateFormat:@"MM"];
    NSDateFormatter *formatter3 = [[NSDateFormatter alloc] init];
    [formatter3 setDateFormat:@"dd"];
    
    int yearNum = [[formatter1 stringFromDate:currentday] intValue];
    int mounthNum = [[formatter2 stringFromDate:currentday] intValue];
    int dayNum = [[formatter3 stringFromDate:currentday] intValue];
    
    int nomarlYear = [year intValue];
    int nomarlMounth = [mounth intValue];
    
    if (yearNum == nomarlYear && mounthNum == nomarlMounth) {
        for (int i = 1; i<=dayNum; i++) {
            NSString *str = [NSString stringWithFormat:@"%d",i];
            [dayArr addObject:str];
        }
    }else{
        //31天
        if (nomarlMounth == 1||nomarlMounth == 3||nomarlMounth == 5||nomarlMounth == 7||nomarlMounth == 8||nomarlMounth == 10||nomarlMounth == 12) {
            for (int i = 1; i<=31; i++) {
                NSString *str = [NSString stringWithFormat:@"%d",i];
                [dayArr addObject:str];
            }
        }else if(nomarlMounth == 4||nomarlMounth==6||nomarlMounth==9||nomarlMounth==11){//30
            for (int i = 1; i<=30; i++) {
                NSString *str = [NSString stringWithFormat:@"%d",i];
                [dayArr addObject:str];
            }
        }else{
            if ((nomarlYear%4==0 && nomarlYear %100 !=0) || nomarlYear%400==0) {
                for (int i = 1; i<=29; i++) {
                    NSString *str = [NSString stringWithFormat:@"%d",i];
                    [dayArr addObject:str];
                }
            }else {
                for (int i = 1; i<=28; i++) {
                    NSString *str = [NSString stringWithFormat:@"%d",i];
                    [dayArr addObject:str];
                }
            }
        }
        
        
        //29
        
        //28
    }
    
    
    
    
    
    
    return dayArr.copy;
}




@end
